package com.Sql;

import java.sql.*;

import org.apache.log4j.Logger;
import com.ibatis.sqlmap.client.SqlMapClient;



public class DatabaseFactory
{
  private static DatabaseFactory instance;
  private static Logger log = Logger.getLogger(DatabaseFactory.class);
  private static String driver;
  private static String url;
  private static String user;
  private static String password;

  public static void setDatabaseSettings(String _driver, String _url, String _user, String _password)
  {
    driver = _driver;
    url = _url;
    user = _user;
    password = _password;
  }

  public void DriverLoad()
  {
    try
    {
      Class.forName(driver);
      log.info("드라이브 로드 : " + driver);
    } catch (Exception e) {
      log.error("드라이브 로드 실패 : " + e.getMessage());
    }
  }

  public DatabaseFactory(String _driver, String _url, String _user, String _password)
    throws SQLException
  {
    driver = _driver;
    url = _url;
    user = _user;
    password = _password;
  }

  public DatabaseFactory()
    throws SQLException
  {
  }

  public void shutdown()
  {
  }

  public static DatabaseFactory getInstance()
    throws SQLException
  {
    if (instance == null) {
      instance = new DatabaseFactory();
    }
    return instance;
  }

  public Connection getConnection()
    throws SQLException
  {
    Connection conn = null;

    DriverLoad();
    conn = DriverManager.getConnection(url, user, password);

    return conn;
  }


  public SqlMapClient getMSSqlMapClient()
  {
    SqlMapClient sqlMap = MySqlConfig.getSqlMapInstance();

    return sqlMap;
  }

 
}